Skip to content

{Profile} Fix #31992: az login: Do not launch SubscriptionSelector when there is no accessible tenant#31997

Open
jiasli wants to merge 1 commit intoAzure:devfrom
jiasli:login-subscriptions
Open

{Profile} Fix #31992: az login: Do not launch SubscriptionSelector when there is no accessible tenant#31997
jiasli wants to merge 1 commit intoAzure:devfrom
jiasli:login-subscriptions

Conversation

@jiasli
Copy link
Copy Markdown
Member

@jiasli jiasli commented Aug 25, 2025

Related command
az login

Description
Fix #31992

az login --allow-no-subscriptions fails when there is no accessible tenant:

  File "/usr/local/Cellar/azure-cli/2.76.0/libexec/lib/python3.12/site-packages/azure/cli/command_modules/profile/custom.py", line 211, in login
    selected = SubscriptionSelector(subscriptions)()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.76.0/libexec/lib/python3.12/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 69, in __call__
    tenant_string = self._get_tenant_string(self._active_one)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.76.0/libexec/lib/python3.12/site-packages/azure/cli/command_modules/profile/_subscription_selector.py", line 98, in _get_tenant_string
    if tenant_display_name := subscription.get(_TENANT_DISPLAY_NAME):
                              ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

This happens when a Microsoft account (not work or school account) is used to log in, but the account is not added to any Entra tenant.

This PR makes az login not launch SubscriptionSelector when there is no accessible tenant.

Testing Guide
Log in with a Microsoft account that doesn't have access to any tenant.

> az login --allow-no-subscriptions
Select the account you want to log in with. For more information on login with Azure CLI, see https://go.microsoft.com/fwlink/?linkid=2271136

Retrieving subscriptions for the selection...

No accessible tenant. Make sure your account has access to at least one tenant.

[Announcements]
...

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Aug 25, 2025

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Hi @jiasli,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Aug 25, 2025

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Aug 25, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

selected = SubscriptionSelector(subscriptions)()
profile.set_active_subscription(selected[_SUBSCRIPTION_ID])
else:
print("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3150 made az login not fail when --allow-no-subscriptions is provided and the user account has no accessible tenant.

@jiasli jiasli force-pushed the login-subscriptions branch from 9c50829 to 0016cc2 Compare January 12, 2026 09:13
@jiasli jiasli marked this pull request as ready for review January 12, 2026 09:14
@jiasli jiasli requested a review from evelyn-ys as a code owner January 12, 2026 09:14
Copilot AI review requested due to automatic review settings January 12, 2026 09:14
@jiasli jiasli requested a review from bebound as a code owner January 12, 2026 09:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where az login --allow-no-subscriptions crashes with an AttributeError when logging in with an account that has no access to any tenant. The fix adds a check to prevent launching the SubscriptionSelector when there are no subscriptions, instead displaying an appropriate error message.

Changes:

  • Added conditional check to only launch SubscriptionSelector when subscriptions list is not empty
  • Added user-friendly error message when no accessible tenant is found
  • Added code comments explaining the behavior when --allow-no-subscriptions is used

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

# When --allow-no-subscriptions is specified, and the account
# - has access to tenant, but no subscription, `subscriptions` will be the tenant account
# - has access to no tenant, `subscriptions` will be []. This line will be hit.
print("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n")
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using logger.warning or logger.error instead of print for the error message to be consistent with CLI logging patterns. Looking at the surrounding code (lines 220), logger.warning is used for warnings, and this seems like an error or warning message that should follow the same pattern.

Suggested change
print("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n")
logger.warning("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Account az login/account act-identity-squad Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'NoneType' object has no attribute 'get' when runing az login

4 participants